84f4e3
@@ -275,6 +275,13 @@
private void configureSession(Map<String, String> sessionConfMap) throws HiveSQL
           throw new HiveSQLException(e);
         }
       } else if (key.startsWith("use:")) {
+        try {
+          if (sessionHive.getDatabase(entry.getValue()) == null) {
+            throw new HiveSQLException("Database " + entry.getValue() + " does not exist");
+          }
+        } catch (HiveException e) {
+          throw new HiveSQLException(e);
+        }
         SessionState.get().setCurrentDatabase(entry.getValue());
       } else {
         sessionConf.verifyAndSet(key, entry.getValue());
